{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-07-30 12:29:13.711\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m48\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-07-30 12:29:13,762\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-07-30 12:29:13,777\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在一片荒芜的星球上，一位孤独的宇航员发现了一株微弱发光的小草。他轻轻地抚摸着它，眼中闪烁着希望的光芒。这株小草成为了他唯一的伙伴，在无尽的孤独中，他们相互依偎，共同等待着救援的到来。</<RESPONSE>在一片荒芜的星球上，一位孤独的宇航员发现了一株微弱发光的小草。他轻轻地\n"
     ]
    }
   ],
   "source": [
    "import byzerllm\n",
    "from byzerllm import ByzerLLM\n",
    "\n",
    "llm = ByzerLLM.from_default_model(\"deepseek_chat\")\n",
    "\n",
    "\n",
    "@byzerllm.prompt()\n",
    "def tell_story() -> str:\n",
    "    \"\"\"\n",
    "    讲一个50字的故事。\n",
    "    \"\"\"\n",
    "\n",
    "\n",
    "s = (\n",
    "    tell_story.with_llm(llm)    \n",
    "    .with_response_markers()\n",
    "    .options({\"llm_config\": {\"max_length\": 10}})\n",
    "    .run()\n",
    ")\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-07-21 22:21:38.891\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m37\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-07-21 22:21:38,930\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-07-21 22:21:38,943\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Generating QA pairs for 祝海林生日是2月1号\n",
      "<_group_>\n",
      "<_question_>祝海林的生日是哪一天？</_question_>\n",
      "<_answer_>祝海林的生日是2月1号。</_answer_>\n",
      "</_group_>\n",
      "\n",
      "<_group_>\n",
      "<_question_>祝海林的出生月份是什么？</_question_>\n",
      "<_answer_>祝海林的出生月份是2月。</_answer_>\n",
      "</_group_>\n",
      "\n",
      "<_group_>\n",
      "<_question_>祝海林的出生日期是几号？</_question_>\n",
      "<_answer_>祝海林的出生日期是1号。</_answer_>\n",
      "</_group_>\n",
      "\n",
      "<_group_>\n",
      "<_question_>祝海林的生日在哪个季节？</_question_>\n",
      "<_answer_>祝海林的生日在冬季。</_answer_>\n",
      "</_group_>\n",
      "\n",
      "<_group_>\n",
      "<_question_>祝海林的生日是否在年初？</_question_>\n",
      "<_answer_>是的，祝海林的生日在年初。</_answer_>\n",
      "</_group_>\n",
      "\n",
      "<_group_>\n",
      "<_question_>祝海林的生日是否在一个月的开始？</_question_>\n",
      "<_answer_>是的，祝海林的生日在一个月的开始。</_answer_>\n",
      "</_group_>\n",
      "\n",
      "<_group_>\n",
      "<_question_>祝海林的生日是否在2月的第一个星期？</_question_>\n",
      "<_answer_>是的，祝海林的生日在2月的第一个星期。</_answer_>\n",
      "</_group_>\n",
      "\n",
      "<_group_>\n",
      "<_question_>祝海林的生日是否在2月的第一个工作日？</_question_>\n",
      "<_answer_>这取决于具体年份的日历安排，但通常情况下，2月1号是2月的第一个工作日。</_answer_>\n",
      "</_group_\n",
      "Generated 8 QA pairs.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-07-21 22:22:02.328\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.apps.byzer_storage.memory_model_based\u001b[0m:\u001b[36mto_qa_pairs\u001b[0m:\u001b[36m186\u001b[0m - \u001b[1mGenerated 8 QA pairs.\u001b[0m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "祝海林的生日是哪一天？ -> 祝海林的生日是2月1号。\n",
      "祝海林的出生月份是什么？ -> 祝海林的出生月份是2月。\n",
      "祝海林的出生日期是几号？ -> 祝海林的出生日期是1号。\n",
      "祝海林的生日在哪个季节？ -> 祝海林的生日在冬季。\n",
      "祝海林的生日是否在年初？ -> 是的，祝海林的生日在年初。\n",
      "祝海林的生日是否在一个月的开始？ -> 是的，祝海林的生日在一个月的开始。\n",
      "祝海林的生日是否在2月的第一个星期？ -> 是的，祝海林的生日在2月的第一个星期。\n",
      "祝海林的生日是否在2月的第一个工作日？ -> 这取决于具体年份的日历安排，但通常情况下，2月1号是2月的第一个工作日。\n"
     ]
    }
   ],
   "source": [
    "import byzerllm\n",
    "from byzerllm import ByzerLLM\n",
    "from byzerllm.apps.byzer_storage.memory_model_based import MemoryManager,TagExtractor\n",
    "llm = ByzerLLM.from_default_model(\"deepseek_chat\")\n",
    "memory_manager = MemoryManager(storage=None,base_dir=\"\",model_name=\"deepseek_chat\")\n",
    "v = memory_manager.to_qa_pairs(\"祝海林生日是2月1号\",llm)\n",
    "for t in v:\n",
    "    print(f\"{t.question} -> {t.answer}\")\n",
    "\n",
    "# v = memory_manager._convert_pretrain_text_to_instruction.with_llm(llm).run(\"祝海林生日是2月1号\")\n",
    "# print(v)\n",
    "# format_v = memory_manager._format.with_llm(llm).run(v)\n",
    "# print(format_v )\n",
    "# root_tag = TagExtractor(v).extract()\n",
    "# print(root_tag)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "byzerllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
